
print("Hello World");

local redis = require 'redis';
local host = "127.0.0.1"
local port = 6379

client = redis.connect(host, port)

redis.call = function(cmd, ...)
    return assert(loadstring('return client:'.. string.lower(cmd) ..'(...)'))(...)
end

--KEYS = {"zset", "hash"};
KEYS = {"msg:like:count:expireZset", "msg:like:countHash"};
--ARGV = {5};
ARGV = {1557821058350};
-- 第一个key是过期时间的zset， 第二个key是用户信息hash
-- 第一个参数是过期时间戳
local expireTimestamp = ARGV[1];

-- 获取过期时间数据
local expireList = redis.call('zrangebyscore', KEYS[1], -1, expireTimestamp);


-- 清除hash中的用户信息
for i = 1, #expireList do
    local delCount = redis.call('hdel', KEYS[2], expireList[i]);
    print(delCount);
end;

-- 清除zset中的过期标识
redis.call('zremrangebyscore', KEYS[1], -1, expireTimestamp);





